<?php

namespace mpend\modules\shop\models;

use Yii;
use common\helpers\Url;
use common\models\shop\ShopAttachment;

/**
 * This is the model class for table "{{%shop_goods}}".
 *
 */
class StockKeepingUnit extends \common\models\shop\ShopGoods {

    /**
     * {@inheritdoc}
     */
    public function fields() {
        $fields = [
            'id',
            'price' => function() {
                return $this->price * 100;
            },
            'stock_num' => 'allowSales',
        ];
        Yii::error($this->activeSpecs);
        if (!empty($this->activeSpecs)) {
            $text = [];
            foreach ($this->activeSpecs as $spec) {
                $fields['s' . $spec->spec_id] = function () use ($spec) {
                    return $spec->spec_value_id;
                };
                $text[] = $spec->spec_value;
            }
            $fields['text'] = function () use ($text) {
                return implode(' ', $text);
            };
        }
        return $fields;
    }

}
